home *** CD-ROM | disk | FTP | other *** search
- Path: cph-2.news.DK.net!dkuug!dknet!usenet
- From: jesk@dk-online.dk (Jes R. Klinke)
- Newsgroups: alt.msdos.programmer,comp.lang.c,comp.lang.pascal.misc
- Subject: Re: typecasting preferences
- Date: Tue, 16 Apr 1996 19:51:26 GMT
- Organization: Customer at DKnet
- Message-ID: <3173fb39.0@193.89.47.9>
- References: <4l020g$i9j@srvr1.engin.umich.edu>
- NNTP-Posting-Host: h9.dk-online.dk
- X-Newsreader: Forte Free Agent 1.0.82
-
- hasdi@news-server.engin.umich.edu (HASDI RODZMANN HASHIM) wrote:
-
- >Hi guys! I think my earlier post got lost so here it is again.... This is
- >for a student compiler project of mine....
-
- >If you have a choice, do you want the parethesis pair over the caster
- >(C-style) or over the castee (Pascal-style)? eg...
-
- >int a;
- >float b;
-
- >a = (int)b; /* cast to int */
- >a = int(b); /* allowable in C++ */
-
- >...as for Pascal...
- >a := integer(b); { "a" in an integer and "b" is a real }
-
- >Thanx!
-
- Hi,
- I like the pascal version because you can easily see what you are
- actually typecasting e.g.
-
- a := 10000; b := 10000;
- c := longint(a * b); { Bad, overflow occurs before typecast }
- c := longint(a) * b; { Good, typecast then multiply }
-
- I don't know how you distinguish between these cases in C++ (I have
- never done any serious programming in C).
- Jes R Klinke
-
-